package grouup3_project4;

import javax.swing.*;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Employee extends Person implements ActionListener
{
	private JFrame frame = new JFrame("Employee");
	public String employeeID, superior;
	private float salary;
	static Employee empl;
	
	public void createEmployee()
	{
		frame.setLayout(new GridLayout(8,2));
		frame.setVisible(true);
		
		frame.add(new JLabel("First Name: "));
		final JTextArea firstNameTextArea = new JTextArea(); 		
		frame.add(firstNameTextArea);
		
		frame.add(new JLabel("Last Name: "));
		final JTextArea lastNameTextArea = new JTextArea();
		frame.add(lastNameTextArea);
		
		frame.add(new JLabel("Age: "));
		final JTextArea ageTextArea = new JTextArea();
		frame.add(ageTextArea);
		
		frame.add(new JLabel("SSN: "));
		final JTextArea ssnTextArea = new JTextArea();
		frame.add(ssnTextArea);
		
		frame.add(new JLabel("Employee ID: "));
		final JTextArea employeeIDTextArea = new JTextArea();
		frame.add(employeeIDTextArea);
		
		frame.add(new JLabel("Salary: "));
		final JTextArea salaryTextArea = new JTextArea();
		frame.add(salaryTextArea);
		
		frame.add(new JLabel("Reports to: "));
		final JTextArea superiorTextArea = new JTextArea();
		frame.add(superiorTextArea);
		
		
		JButton submit = new JButton("Submit");
		submit.addActionListener(new ActionListener() 
		{	
			@Override
			public void actionPerformed(ActionEvent e) 
			{
				int age = Integer.parseInt(ageTextArea.getText());
				float salary = Float.parseFloat(salaryTextArea.getText());
				
				empl = new Employee(firstNameTextArea.getText(), lastNameTextArea.getText(), age, 
						ssnTextArea.getText(), employeeIDTextArea.getText(), salary, superiorTextArea.getText()); 			
			}
		});
		frame.add(submit);
		
		JButton cancel = new JButton("Cancel");
		cancel.addActionListener(new ActionListener() 
		{	
			@Override
			public void actionPerformed(ActionEvent e) 
			{
				frame.dispose(); 			
			}
		});

		frame.add(cancel);
		frame.pack();
	}
	
	
	
	
	
	public Employee()
	{		
	}	
	public Employee(String firstName, String lastName, int age, String ssn, String employeeID, float salary, String superior)
	{
		super(firstName, lastName, age, ssn);
		this.employeeID = employeeID;
		this.setSalary(salary);
		this.superior = superior;
		System.out.println(this);
	}
	public float getSalary() 
	{
		return salary;
	}
	public void setSalary(float salary) 
	{
		this.salary = salary;
	} 

	
	
	
	
	@Override
	public String toString()
	{
		return "First Name: " + this.firstName + "\nLastName: " + this.lastName + "\nAge: " + this.age + "\nSSN: " + this.getSsn()
				+ "\nStudent Id: " + this.employeeID + "\nSalary: " + this.getSalary() + "\nReports to: " + this.superior;
	}
	@Override
	public void actionPerformed(ActionEvent e) 
	{
		frame.dispose();
	}
}
